<?php include "../public/header.php";?>
<style>
    .canDiv{width: calc(100% -2px);height: 300px;text-align: center;margin-top: 50px}
    .canDiv .cont{width: 700px;height: 300px;border: 1px solid #ccc;margin: 0 auto}
    .btn-reset{background-color: #aaa!important;}
</style>
<body style="overflow: hidden">
<form class="layui-form flow_opt_page">
    <div class="mainBox">
        <div class="title-box">
            <span class="title">手写签名</span>
            <div class="move_title"></div>
            <div class="title-box-opt">
                <button type="button" class="layui-btn layui-btn-sm btn-reset marginr5" style="line-height: 28px!important;" id="clearrect">重置</button>
                <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" style="line-height: 28px!important;" lay-submit="" lay-filter="add">提交</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>


        <div class="canDiv">
            <div class="cont">
                <canvas id="canvas" width = "700" height = "300"></canvas>
            </div>
        </div>



    </div>
</form>
<script src='/static/admin/js/sign.js'></script>
<script>
    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;


        form.on('submit(add)', function(data){
            var qianfile = getcanurl()
            if(qianfile === false){
                return false;
            }

            var loading = layui.layer.load(0, {shade: 0.1});
            let fd = new FormData();
            fd.append('file', qianfile);
            fd.append('token', facade.getCookie('token'));
            $.ajax({
                url: server_api_name+ask_upload_file,
                type: "POST",
                data: fd,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (res) {
                    layui.layer.close(loading);
                    if (res.code === 2000) {
                        $("#qian_id" , parent.document).val(res.data.id);
                        $("#qian" , parent.document).val(res.data.encpath);
                        $(".signshen .deadea" , parent.document).addClass('layui-hide');
                        $(".signshen .deazhen" , parent.document).removeClass('layui-hide');
                        $(".signshen .deazhen img" , parent.document).attr('src', get_file_complete(res.data.encpath));
                        layer_close();
                    }else{
                        facade.error(res.data.msg);
                    }
                },
                error: function (res) {
                    layui.layer.close(loading);
                    facade.error("网络错误");
                },
            })

            return false;
        });

    });

</script>
</body>
</html>
